using System.IO;
using UnityEditor;
namespace IFramework
{
    public class FormatUIScript
    {
        public static string NewScriptName { get { return newScriptName; } set { newScriptName = value; } }
        public static string OriginScriptPath { get { return originScriptPath; } set { originScriptPath = value; } }
        private static string newScriptName = "UIScript.cs";
        private static string originScriptPath = FrameWorkInfo.GetFrameWorkEditorPath(). CombinePath(@"CopyAsset/UIBaseScript.txt");

        [MenuItem("Assets/IFramework/UIBaseScript")]
        public static void CreateUIBase()
        {
            CreateOriginIfNull();
            CopyAsset.CopyNewAsset(NewScriptName,originScriptPath);
        }

        public static  void CreateOriginIfNull()
        {
            if (File.Exists(OriginScriptPath)) return;
            using (FileStream fs = new FileStream(originScriptPath, FileMode.Create, FileAccess.Write))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    fs.Lock(0, fs.Length);
                    sw.WriteLine("/*********************************************************************************");
                    sw.WriteLine(" *Author:         #AUTHOR#");
                    sw.WriteLine(" *Version:        #VERSION#");
                    sw.WriteLine(" *UnityVersion:   #UNITYVERSION#");
                    sw.WriteLine(" *Date:           #DATE#");
                    sw.WriteLine(" *Description:    ");
                    sw.WriteLine(" *History:        ");
                    sw.WriteLine("*********************************************************************************/");
                    sw.WriteLine("using IFramework;");
                    sw.WriteLine("using UnityEngine;");
                    sw.WriteLine("");
                    sw.WriteLine("public class #SCRIPTNAME#Data : UIData");
                    sw.WriteLine("{");
                    sw.WriteLine("\tpublic void ReFresh()");
                    sw.WriteLine("\t{");
                    sw.WriteLine("\t");
                    sw.WriteLine("\t}");
                    sw.WriteLine("}");
                    sw.WriteLine("public class #SCRIPTNAME# : UIBase");
                    sw.WriteLine("{");
                    sw.WriteLine("\tpublic override void OnEnter(params object[] paras)");
                    sw.WriteLine("\t{");
                    sw.WriteLine("\t\tbase.OnEnter(paras);");
                    sw.WriteLine("\t\t//do sth");
                    sw.WriteLine("\t}");
                    sw.WriteLine("\t");
                    sw.WriteLine("\tpublic override void SetViewData()");
                    sw.WriteLine("\t{");
                    sw.WriteLine("\t\tif (data==null)");
                    sw.WriteLine("\t\t{");
                    sw.WriteLine("\t\t\tdata = new #SCRIPTNAME#Data();");
                    sw.WriteLine("\t\t}");
                    sw.WriteLine("\t\tbase.SetViewData();");
                    sw.WriteLine("\t\t//do sth");
                    sw.WriteLine("\t}");
                    sw.WriteLine("\t");
                    sw.WriteLine("\tpublic override void OnExit(params object[] paras)");
                    sw.WriteLine("\t{");
                    sw.WriteLine("\t\t//do sth");
                    sw.WriteLine("\t\tbase.OnExit(paras);");
                    sw.WriteLine("\t}");
                    sw.WriteLine("\t");
                    sw.WriteLine("\tpublic override void OnClean(params object[] paras)");
                    sw.WriteLine("\t{");
                    sw.WriteLine("\t\tbase.OnClean(paras);");
                    sw.WriteLine("\t\t//do sth");
                    sw.WriteLine("\t}");
                    sw.WriteLine("\t");
                    sw.WriteLine("}");
                    try
                    {
                        fs.Unlock(0, fs.Length);
                    }
                    catch (System.Exception)
                    {

                    }
                    sw.Flush();
                    fs.Flush();
                }
            }
            AssetDatabase.Refresh();
        }
    }
}
/*********************************************************************************
 *Author:       OnClick
 *Version:      1.0
 *UnityVersion: 2017.2.3p3
 *Date:         2019-01-26
 *Description:   
 *History:  
**********************************************************************************/
